<?php
class Smarty_Internal_Compile_Zphnet extends Smarty_Internal_CompileBase{
    public $required_attributes = array('item');
    public $optional_attributes = array('name', 'key', 'len', 'limit', 'ispage','state');
    public $shorttag_order = array('from', 'item', 'key', 'name');
    public function compile($args, $compiler, $parameter){
        $_attr = $this->getAttributes($compiler, $args);

        $from = $_attr['from'];
        $item = $_attr['item'];
        $name = $_attr['item'];
        $name=str_replace('\'','',$name);
        $name=$name?$name:'list';$name='$'.$name;
        if (!strncmp("\$_smarty_tpl->tpl_vars[$item]", $from, strlen($item) + 24)) {
            $compiler->trigger_template_error("item variable {$item} may not be the same variable as at 'from'", $compiler->lex->taglineno);
        }
        
        //自定义标签START
        $OutputStr=''.$name.'=array();$time=time();$paramer='.ArrayToString($_attr,true).';
		global $db,$db_config,$config;
		$ParamerArr = GetSmarty($paramer,$_GET,$_smarty_tpl);
		$paramer = $ParamerArr[arr];
		$Purl =  $ParamerArr[purl];
        global $ModuleName;
        if(!$Purl["m"]){
            $Purl["m"]=$ModuleName;
        }
		$where = "1";
		
		if($config[\'did\']){
			$where.=" and `did`=\'".$config[\'did\']."\'";
		}
		//查询条数
		if($paramer[limit]){
			$limit=" LIMIT ".$paramer[limit];
		}else{
			$limit=" LIMIT 20";
		}
		if($paramer[ispage]){
			$limit = PageNav($paramer,$_GET,"zphnet",$where,$Purl,"",6,$_smarty_tpl);
		}
        // 查询招聘列表，判断有没有未结束的招聘会，确定排序
        $zphlist  =  $db->DB_select_once("zphnet","unix_timestamp(`endtime`)>\'$time\'","`id`");
        // 有未结束的，条件查询
        if(!empty($zphlist)){
            // 条件排序，进行中在最上面，接着是未开始，最后是已结束
    		$where .= " ORDER BY CASE";
            $where .= " WHEN unix_timestamp(`starttime`)<\'$time\' AND unix_timestamp(`endtime`)>\'$time\' THEN 0";
            $where .= " WHEN unix_timestamp(`starttime`)>\'$time\' THEN 1";
            $where .= " WHEN unix_timestamp(`endtime`)<\'$time\' THEN 2";
            $where .= " END, unix_timestamp(`starttime`) ASC";
        }else{
            // 全部结束。按时间开始时间倒序排列
            $where .= " unix_timestamp(`starttime`) DESC";
        }
        
		'.$name.'=$db->select_all("zphnet",$where.$limit);
		if(is_array('.$name.')){
			foreach('.$name.' as $key=>$v){
				'.$name.'[$key]["starttime_n"]=date(\'Y-m-d H:i\',strtotime($v[starttime]));
                '.$name.'[$key]["endtime_n"]=date(\'Y-m-d H:i\',strtotime($v[endtime]));
				'.$name.'[$key]["stime"]=strtotime($v[starttime])-time();
				'.$name.'[$key]["etime"]=strtotime($v[endtime])-time();
				if($paramer[len]){
					'.$name.'[$key]["title"]=mb_substr($v[\'title\'],0,$paramer[len],"utf-8");
				}
				'.$name.'[$key]["url"]=Url("zphnet",array("c"=>\'show\',"id"=>$v[\'id\']),"1");
				
				'.$name.'[$key][\'pic\'] = checkpic($v[\'pic\'],$config[\'sy_zph_icon\']);
			}
		}';
        //自定义标签 END
        return SmartyOutputStr($this,$compiler,$_attr,'zphnet',$name,$OutputStr,$name);
    }
}
class Smarty_Internal_Compile_Zphnetselse extends Smarty_Internal_CompileBase{
    public function compile($args, $compiler, $parameter){
        $_attr = $this->getAttributes($compiler, $args);

        list($openTag, $nocache, $item, $key) = $this->closeTag($compiler, array('zphnet'));
        $this->openTag($compiler, 'zphnetelse', array('zphnetelse', $nocache, $item, $key));

        return "<?php }\nif (!\$_smarty_tpl->tpl_vars[$item]->_loop) {\n?>";
    }
}
class Smarty_Internal_Compile_Zphnetclose extends Smarty_Internal_CompileBase{
    public function compile($args, $compiler, $parameter){
        $_attr = $this->getAttributes($compiler, $args);
        if ($compiler->nocache) {
            $compiler->tag_nocache = true;
        }

        list($openTag, $compiler->nocache, $item, $key) = $this->closeTag($compiler, array('zphnet', 'zphnetelse'));

        return "<?php } ?>";
    }
}
